package com.xiaoge.libraryuse.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;

import com.blankj.utilcode.util.ActivityUtils;
import com.blankj.utilcode.util.BarUtils;
import com.xiaoge.basedevlibrary.base.GuoBaseActivity;
import com.xiaoge.basedevlibrary.base.GuoBaseAppLication;
import com.xiaoge.basedevlibrary.utils.AppUtil;
import com.xiaoge.basedevlibrary.utils.IntentUtils;
import com.xiaoge.basedevlibrary.utils.StatusBarUtil;
import com.xiaoge.basedevlibrary.utils.ToastUtil;
import com.xiaoge.libraryuse.R;
import com.xiaoge.libraryuse.banner.BannerActivity;
import com.xiaoge.libraryuse.interface_call_back.InterfaceCallBackActivity;
import com.xiaoge.libraryuse.recycler.RecyclerActivity;
import com.xiaoge.libraryuse.table1.TableActivity1;
import com.xiaoge.libraryuse.table2.TableActivity2;
import com.xiaoge.libraryuse.table3.TableActivity3;
import com.xiaoge.libraryuse.tablelayout.TableActivity;

import org.xutils.DbManager;

public class MainActivity extends GuoBaseActivity implements View.OnClickListener {

    private LinearLayout content;
    private Button request_http;
    private Button recycler;
    private Button banner;
    private Button table;
    private Button web;
    private Button dialog;
    private Button table1;
    private Button table2;
    private Button table3;
    private Button youhua;//右滑删除
    private Button leftIn;//左进右出
    private Button smartRefresh;//下拉刷新
    private Button videoList;//视频列表
    private Button interfaceCallBack;//接口回调
    private Button Tbs;//Tbs内核


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // 设置状态栏透明
        StatusBarUtil.darkMode(mActivity);

        initView();
    }

    private void initView() {
        request_http = (Button) findViewById(R.id.request_http);
        recycler = (Button) findViewById(R.id.recycler);
        banner = (Button) findViewById(R.id.banner);
        table = (Button) findViewById(R.id.table);
        content = (LinearLayout) findViewById(R.id.content);
        web = (Button) findViewById(R.id.web);

        // 设置全屏展示的时候 将根布局增加一个状态栏的高度
        BarUtils.addMarginTopEqualStatusBarHeight(content);

        request_http.setOnClickListener(this);
        recycler.setOnClickListener(this);
        banner.setOnClickListener(this);
        table.setOnClickListener(this);
        web.setOnClickListener(this);
        dialog = (Button) findViewById(R.id.dialog);
        dialog.setOnClickListener(this);
        table1 = (Button) findViewById(R.id.table1);
        table1.setOnClickListener(this);
        table2 = (Button) findViewById(R.id.table2);
        table2.setOnClickListener(this);
        table3 = (Button) findViewById(R.id.table3);
        table3.setOnClickListener(this);
        youhua = (Button) findViewById(R.id.right_huadong);
        youhua.setOnClickListener(this);
        leftIn = (Button) findViewById(R.id.left_in);
        leftIn.setOnClickListener(this);
        smartRefresh = (Button) findViewById(R.id.smart_refresh);
        smartRefresh.setOnClickListener(this);
        videoList = (Button) findViewById(R.id.video_play);
        videoList.setOnClickListener(this);
        interfaceCallBack = (Button) findViewById(R.id.interface_callback);
        interfaceCallBack.setOnClickListener(this);
        Tbs = (Button) findViewById(R.id.tbs_x5);
        Tbs.setOnClickListener(this);

        DbManager db = ((GuoBaseAppLication) getApplication()).getDb();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.request_http:
                Intent intent = new Intent(MainActivity.this, HttpActivity.class);
                IntentUtils.startActivity(MainActivity.this, intent);
                break;
            case R.id.recycler:
                Intent intent2 = new Intent(MainActivity.this, RecyclerActivity.class);
                IntentUtils.startActivity(MainActivity.this, intent2);
                break;
            case R.id.banner:
                Intent intent3 = new Intent(MainActivity.this, BannerActivity.class);
                IntentUtils.startActivity(MainActivity.this, intent3);
                break;
            case R.id.table:
                Intent intent4 = new Intent(MainActivity.this, TableActivity.class);
                IntentUtils.startActivity(MainActivity.this, intent4);
                break;
            case R.id.web:
                Intent intent5 = new Intent(MainActivity.this, WebViewActivity.class);
                IntentUtils.startActivity(MainActivity.this, intent5);
                break;
            case R.id.dialog:
                Intent intent6 = new Intent(MainActivity.this, LoadingStateActivity.class);
                IntentUtils.startActivity(MainActivity.this, intent6);
                break;
            case R.id.table1:
                Intent intent7 = new Intent(MainActivity.this, TableActivity1.class);
                IntentUtils.startActivity(MainActivity.this, intent7);
                break;
            case R.id.table2:
                Intent intent8 = new Intent(MainActivity.this, TableActivity2.class);
                IntentUtils.startActivity(MainActivity.this, intent8);
                break;
            case R.id.table3:
                Intent intent9 = new Intent(MainActivity.this, TableActivity3.class);
                IntentUtils.startActivity(MainActivity.this, intent9);
                break;
            case R.id.right_huadong:
                Intent intent10 = new Intent(MainActivity.this, RightSliderActivity.class);
                IntentUtils.startActivity(MainActivity.this, intent10);
                break;
            case R.id.left_in:
                Intent intent11 = new Intent(MainActivity.this, LeftInRightOutActivity.class);
                IntentUtils.startActivity(MainActivity.this, intent11);
                break;
            case R.id.smart_refresh:
                Intent intent12 = new Intent(MainActivity.this, SmartRefreshLayoutActivity.class);
                IntentUtils.startActivity(MainActivity.this, intent12);
                break;
            case R.id.video_play:
                Intent intent13 = new Intent(MainActivity.this, VideoListActivity.class);
                IntentUtils.startActivity(MainActivity.this, intent13);
                break;
            case R.id.interface_callback:
                Intent intent14 = new Intent(MainActivity.this, InterfaceCallBackActivity.class);
                IntentUtils.startActivity(MainActivity.this, intent14);
                break;
            case R.id.tbs_x5:
                Intent intent15 = new Intent(MainActivity.this, TBSActivity.class);
                IntentUtils.startActivity(MainActivity.this, intent15);
                break;
            default:
                break;
        }
    }

    /**
     * 再按一次退出程序
     */
    private long exitTime = 0;

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) {
            if ((System.currentTimeMillis() - exitTime) > 2000) {
                ToastUtil.showToast(AppUtil.getContext(), "再按一次退出程序");
                exitTime = System.currentTimeMillis();
            } else {
                ActivityUtils.finishAllActivities();
            }
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }
}
